const Config = require("../project/project_config.js");
const ProjectRequest = require("../project/project_request.js");
const Url = require("../utils/url.js");
const Log = require("../utils/core_log.js");
const Tool = require("../utils/tool.js");
const Login = require("../utils/privacy_login.js");
const GainPhone = require("../utils/privacy_gainPhone.js");

/**
 * 在线充值
 */
function createRechargeOrder(amount,  callback) {
  const url = "/user/recharge/create";
  ProjectRequest.postRequest(url, { amount: amount}, callback);
}

/**
 * 线下充值
 */
function submitRechargeOrder(amount, callback) {
  const url = "/user/recharge/submit";
  ProjectRequest.postRequest(url, { amount: amount }, callback);
}

/**
 * 积分列表
 */
function scorePage(startPage, callback) {
  const url = "/user/score/page?startPage=" + startPage;
  ProjectRequest.getRequest(url, callback);
}

/**
 * 得到账户金额
 */
function getUserAmount(callback) {
  const url = "/user/score/get";
  ProjectRequest.getRequest(url, callback);
}

/**
 * 得到用户信息
 */
function getInfo(callback) {
  const url = "/user/info/get";
  // 发送请求
  ProjectRequest.getRequest(url, callback);
}

/**
 * 得到客户列表
 */
function getCustomPage(startPage, callback) {
  const url = "/user/custom/page?startPage=" + startPage;
  ProjectRequest.getRequest(url, callback);
}

/**
 * 得到代理
 */
function getProxysPage(startPage, callback) {
  const url = "/user/proxy/page?startPage=" + startPage;
  // 发送请求
  ProjectRequest.getRequest(url, callback);
}

/**
 * 编辑代理地址
 */
function editProxyAddress(data, callback) {
  const url = "/user/proxy/address";
  ProjectRequest.postRequest(url, data, callback);
}

/** 
 * 绑定关系
 */
function bind(companyStaffId, callback) {
  const url = "/user/bind?companyStaffId=" + companyStaffId;
  ProjectRequest.getRequest(url, callback);
}

/**
 * 编辑账号_姓名
 */
function editAccountName(data, callback) {
  const url = "/user/account/edit/name";
  ProjectRequest.postRequest(url, data, callback);
}

/**
 * 编辑账号_公司名称
 */
function editAccountCompany(data, callback) {
  const url = "/user/account/edit/company";
  ProjectRequest.postRequest(url, data, callback);
}

/**
 * 编辑账号_账号
 */
function editAccountNumber(data, callback) {
  const url = "/user/account/edit/account";
  ProjectRequest.postRequest(url, data, callback);
}

/**
 * 编辑账号_开户行
 */
function editAccountBank(data, callback) {
  const url = "/user/account/edit/bank";
  ProjectRequest.postRequest(url, data, callback);
}

/**
 * 获取账号信息
 */
function getAccount(callback) {
  const url = "/user/account/get";
  ProjectRequest.getRequest(url, callback);
}

/**
 * 获取电话
 */
function gainPhone(_e, _callbak){
  const URL = Url
    .newInstance('/user/account/gain/phone')
    .setPara('skey', Login.getLoginSkey());
  GainPhone.gainPhone(_e, Config.Hostname, Config.Port, URL.get(), function(res){
    const data = res.data;
    if (data.type == 'Data') {
      _callbak(data.data, res);
    } else if (data.type == 'Validate') {
      Tool.showInfo(data.data.object);
    } else {
      Log.error(logCallerName, res)
      Tool.showInfo('返回结果错误');
    }
  });
}

/**
 * exports
 */
module.exports = {
  submitRechargeOrder, createRechargeOrder,
  scorePage, getUserAmount,
  getInfo,
  getCustomPage,
  getProxysPage,
  editProxyAddress,
  bind,
  editAccountName, editAccountCompany, editAccountNumber, editAccountBank, getAccount, gainPhone
};